package com.thtf.homework.service.Impl;

import com.thtf.homework.mapper.DataSourceMapper;
import com.thtf.homework.model.DataSource;
import com.thtf.homework.service.DataSourceService;
import org.springdoc.core.service.RequestBodyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

import com.thtf.homework.util.MD5;

@Service
public class DataSourceServiceImpl implements DataSourceService {
    @Autowired
    private DataSourceMapper dataSourceMapper;
    @Autowired
    private RequestBodyService requestBodyBuilder;

    // 创建数据源
    @Override
    public void create(String dataSourceStruct, String dataSourceType, String dataSourceClassification, String dataSourceName, String dataSourceURL, String dataSourceUsername, String dataSourcePassword, String dataSourceMode, String dataSourceDescription) {
        // 加密：工具类
        // UUID
//        UUID uuid = UUID.randomUUID();
//        System.out.println(uuid.toString());


        dataSourceMapper.add(dataSourceStruct, dataSourceType, dataSourceClassification, dataSourceName,
                dataSourceURL, dataSourceUsername, MD5.encrypt(dataSourcePassword), dataSourceMode, dataSourceDescription, UUID.randomUUID().toString());
    }

    // 查询数据源
    @Override
    public List<DataSource> query(String dataSourceClassification) {
        List<DataSource> d = dataSourceMapper.query(dataSourceClassification);
//        System.out.print(d);
        return d;

    }

    // 更新数据源
    @Override
    public void update(String dataSourceClassification, String dataSourceName, String dataSourceURL,
                       String dataSourceUsername, String dataSourcePassword, String dataSourceMode,
                       String dataSourceDescription, String dataSourceID) {


        dataSourceMapper.update(dataSourceClassification, dataSourceName, dataSourceURL, dataSourceUsername,
                MD5.encrypt(dataSourcePassword), dataSourceMode, dataSourceDescription, dataSourceID);
    }

    //删除数据源
    @Override
    public void delete(String dataSourceId) {
        dataSourceMapper.delete(dataSourceId);
    }

}
